/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain;

/**
 *
 * @author Administrator
 */
public class Map {


    public static int MAP_WIDTH = 10;
    public static int MAP_HEIGHT = 10;

    MapNode[][] nodes = new MapNode[MAP_WIDTH][MAP_HEIGHT];

    public Map() {
        for(int x=0;x<MAP_WIDTH;x++)
        {
        for(int y=0;y<MAP_HEIGHT;y++)
        {

           nodes[x][y]= new MapNode();
           nodes[x][y].setX(x);
           nodes[x][y].setY(y);
           nodes[x][y].init();
        }
        }
    }

    public MapNode getWNode(NewsArticle na)
    {
        int bestx =0,besty  = 0;
        double bestDist=Double.MAX_VALUE,cdist=0;
        for(int x=0;x<MAP_WIDTH;x++)
        {
        for(int y=0;y<MAP_HEIGHT;y++)
        {
            cdist= na.distanta(nodes[x][y]);
           if(cdist< bestDist)
           {
            if(cdist==0)
                return nodes[x][y];

             bestx=x;
             besty=y;
             bestDist=cdist;
           }
        }
        }
        return nodes[bestx][besty];
    }
    public MapNode getNode(int x,int y)
    {
        return nodes[x][y];
    }
}
